home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / systems / mac / textures_figs / figure.macros / Figure_macros.tex < prev    next >
Text File  |  1992-01-06  |  62KB  |  1,123 lines

  1. % FIGURE HANDLING MACROS (written by P. Galko,  Aug 13/90)
  2. % ⌐ P. Galko
  3. %
  4. % CHANGE HISTORY:
  5. % ==============
  6. % Addition of the \incposition macro and the \captionbaselineskip
  7. % parameter (controls linespacing in captions), and changes to stop using 
  8. % \count0 through \count4. Small changes to text as well.         Jan.  6/92  
  9. % -
  10. % Additions to the explanatory text, correction of the \scaledfigure macro
  11. %  (the provision for an external pictfile had been missing), correction to the
  12. %  \scaledepsffigure macro, the addition of the missing definition of \@pictf,
  13. %  addition of the ability to shift figures horizontally without bounding box
  14. %  changes, changes to the \checknumber macro to allow EPSF bounding box 
  15. %  values to be any real number [Illustrator 3.2 can produce this, although
  16. %  Adobe's own documentation states that conforming EPSF 3.0 files have only
  17. %  integer valued coordinates in the %%BoundingBox statement.]    Dec. 19/91
  18. % -
  19. % Changes to explanatory text, the addition of the three macros to handle 
  20. %  epsf files more automatically (\epsffigure, \scaledepsfigure, and 
  21. %  \stretchedepsffigure), and a modification in the computation of dimensions
  22. %  with scaled objects was made so that the computation is almost absolutely
  23. %  accurate (the error in computing scaled values before was between 0 and
  24. %  .01524pt * [the scaling factor] which is almost always negligible on a 300dpi
  25. %  printer where 1 pixel is about .24pt; thus this improvement is unlikely to be
  26. %  noticed except in very delicate situations or when scale factors are
  27. %  significantly larger than 15 [i.e., scaled by 15000]).         Sept.27/91
  28. % -
  29. % Corrected \hboxmax macro                                        Feb. 11/91
  30. % -
  31. % Updated to allow for the possibility of PICT file (the "\special pictfile"  
  32. %   option added in Textures 1.3).                                Feb.  2/91 
  33. % -
  34. % Modified to add "\par" after $$ in scaledfigure and figure macros to stop 
  35. %  the possibility of page breaks between a figure and its caption (an 
  36. %  empty box with glue was formerly being added there).           Jan.  8/91 
  37. % -
  38. % Editorial changes clarifying things further                                                                                    Aug. 21/90 
  39. % -
  40. % The example macro was corrected ("i" in param #1 should have been "epsf") 
  41. %   and added a \reposition figure placement command.             Aug. 20/90 
  42. %
  43. % This is a collection of macros which is intended to make the task of importing
  44. % drawing into Textures documents easier. The main macro is the \figure macro.
  45. % It will insert a named graphic object in the typeset document and centering
  46. % it on the full current line according to the object dimensions given to the
  47. % macro (or determined from the BoundingBox comments in the epsf file in the
  48. % case of the \epsffigure and \scaledepsffigure macros). To properly understand
  49. % how this works, you need to understand that on the Macintosh there are
  50. % different ways in which graphic objects are stored.  These storage methods
  51. % are discussed briefly below.
  52. %
  53. % PICT and EPSF:
  54. % =============
  55. % When an object is drawn on a Macintosh screen, the Macintosh is using a
  56. % description of the object given in its own graphic language called
  57. % Quickdraw. When you want to print the picture, the printer driver may take
  58. % this Quickdraw description and convert it to instructions which the printer
  59. % needs to produce (hopefully) the same result.  Quickdraw, however, has certain 
  60. % limitations on its graphic powers arising from its being tailored to the
  61. % limited resolution of the 72 dpi Mac screen.  As a result, when the printing of
  62. % a graphic object rendition occurs in the manner just described, the quality of
  63. % the printed image suffers with respect to the drawer's original intention (not
  64. % the Mac screen) even if the printer is inherently capable of greater resolution.
  65. % Many printers (such as the LaserWriter printers) are capable of much better
  66. % resolution than the Macintosh screen provides and often have other graphic
  67. % languages built-in to them that are more powerful than Quickdraw.  A
  68. % particularly widely used class of printers are those which use PostScript to
  69. % describe everything to be printed.  PostScript is a powerful graphic language
  70. % developed by Adobe Systems Incorporated which has become an industry standard
  71. % for page description.  It allows a graphic object to be described intrinsically
  72. % without worrying much about the resolution of the printer. It is the printer
  73. % and the PostScript interpreter on a particular printer which completes the
  74. % task of building the raster image of the graphic object. There are PostScript
  75. % printers available with a variety of resolutions from 300 dpi all the way to
  76. % 1800 dpi (and perhaps higher).  The Apple LaserWriter II NT, and NTX printers
  77. % are 300 dpi PostScript printers, while Apple's newest printers the LaserWriter
  78. % IIf and IIg are said to effectively have a resolution of 600 dpi (they are
  79. % not true 600 dpi printers however).  Besides providing flexibility and much
  80. % better resolution, PostScript also provides special effects not available
  81. % in Quickdraw (for example, Quickdraw is incapable of writing *directly* text
  82. % at an angle).  Since there is no direct correspondence between PostScript
  83. % and Quickdraw, programs which want to produce high quality results on
  84. % PostScript printers must effectively produce two descriptions of a drawing
  85. % in the end: a Quickdraw description and a PostScript description (actually,
  86. % what some programs do is to generate their own special description of
  87. % graphical objects which they can then translate into Quickdraw [in some
  88. % rough form] and PostScript).
  89. %
  90. % In the Macintosh world their are a few common forms that are used for
  91. % defining or storing pictures. When a Quickdraw description of a graphic object
  92. % is stored, it is stored in "PICT format", either as a PICT file or as a
  93. % PICT resource in another type of file (resources are like small subfiles
  94. % stored in the resource fork of a Macintosh file [every Macintosh file is
  95. % actually two files which are described as the two forks of the file: a data
  96. % fork and a resource fork]). (There is actually a few variants of the PICT
  97. % format, but thats a minor detail.)  Since every application can draw a graphic
  98. % object on the screen, it can usually deal with PICT descriptions; Textures is no
  99. % exception and can import these PICT defined objects and place them in resources
  100. % in the resource fork of the file holding your TeX source and the typeset
  101. % results file, or it can read them from an external PICT file (as can be
  102. % produced by MacDraw). When placed as resources in your document, these can be
  103. % viewed in the pictures window in Textures. To bring in a drawing into the
  104. % pictures window you simply use the cut and paste operations either with the
  105. % clipboard, the scrapbook, or if you are running Multifinder (or System
  106. % 7) seemingly directly between applications. (The source of your TeX file is
  107. % stored in the data fork of a Textures file, with the DVI of the typeset
  108. % result stored in the resource fork [one resource for the DVI output for each
  109. % separate page] along with the PICT resources defining pictures.) 
  110. % Unfortunately since such graphic object descriptions can commonly run in size
  111. % to 50 kilobytes or more, if a document has many such drawings in it, it can
  112. % become very large in size and therefore unwieldy.
  113. % The PICT format was defined well before PostScript appeared on the scene,
  114. % and allowed only Quickdraw commands to be part of the file.  For the reasons
  115. % mentioned above, it was felt desirable to allow PostScript descriptions of
  116. % of objects to be included in these files as well. This was accomplished by
  117. % making use of the comment command in Quickdraw: if a program wants to make use
  118. % of PostScript for printing, it simply includes all the necessary commands as
  119. % comments in the PICT description (which makes the PICT file or resource more
  120. % than twice as long).  Such PICT files have two complete descriptions stored
  121. % along with a significant amount of overhead, and any Mac application reading
  122. % them needs to skip over a lot of material. To make matters more efficient,
  123. % another format was developed to store the Quickdraw and PostScript
  124. % descriptions known as Encapsulated PostScript Format (EPSF).  In this format,
  125. % the two graphic object descriptions are stored as separate parts of a Macintosh
  126. % file, with the Quickdraw description stored in the resource fork of the file, 
  127. % and the PostScript description stored in the data fork. Most drawing programs
  128. % either use EPSF to store objects (e.g., Adobe Illustrator) or are capable of
  129. % generating EPSF files for the drawings they produce (e.g., Freehand and
  130. % Cricket Draw).  Textures is able to incorporate any EPSF specified object into
  131. % a document. An EPSF document does not become part of a Textures file, which 
  132. % keeps the Textures document size down to reasonable size.  EPSF files have an
  133. % additional advantage which is that they are simply text files (albeit
  134. % possibly with some resources in the data fork) and usually contain explicitly
  135. % some information that is useful to properly handle the image in other documents. 
  136. % Each graphic object file format, whether Quickdraw or PostScript, contains
  137. % the specification of a bounding box for the object---an imaginary rectangular
  138. % box with sides parallel to the coordinate axes which in theory should just
  139. % surround the object, but in practice is often made a little bit larger than just
  140. % this.  Textures uses the relation between the lower left hand corner of this
  141. % bounding box and the rest of the object to control placing of the object.  When
  142. % a PICT image is copied in the picture window, the dimensions of the object that
  143. % Textures reports is based only on this bounding box. If you need to, you can
  144. % read the data fork of an EPSF file to find the bounding box location in
  145. % this case, but this is often unnecessary.  All EPSF files must follow a
  146. % particular format established by Adobe (there are actually a few different
  147. % versions of this format, but for our purposes the differences are not
  148. % material; the latest version is version 3.0 which is documented in Appendix H
  149. % of the PostScript Language Reference Manual, 2nd ed., Addison-Wesley, 1990).
  150. % These files besides carrying the PostScript commands to draw the picture, 
  151. % have comment lines which provide various pieces of information about the 
  152. % illustration.  The bounding box is provided as one of the first few lines in
  153. % a statement of the form
  154. %              %%BoundingBox llx lly urx ury
  155. % where (llx,lly) are the coordinates of the lower left hand corner of the
  156. % bounding box and (urx,ury) are the coordinates of the upper right corner.
  157. % Units are in pixels (72 pixels/inch) or what is referred to as 'big points'
  158. % in TeX.
  159. %
  160. % When it was indicated above that an EPSF file had a QuickDraw version of the
  161. % figure in it resource fork, it was not entirely true.  The EPSF format does
  162. % not *require* that a QuickDraw version be included and some programs like
  163. % Illustrator allow you to choose whether or not to place a QuickDraw version
  164. % in the EPSF file (and what version of such a QuickDraw 'preview' to use if
  165. % this is to be included).  If no QuickDraw version is included in the EPSF
  166. % file, Textures will not draw the figure in the preview window---you will only
  167. % see the figure when the document is printed on a PostScript printer.
  168. % Here is an example of the first few lines from the data fork [the PostScript
  169. % part] of an EPSF file 'Test Figure' generated by Adobe Illustrator 3.2 (the
  170. % lines begin with the % character after the blanks):
  171. %
  172. %        %!PS-Adobe-3.0 
  173. %        %%Creator: Adobe Illustrator(TM) 3.2
  174. %        %%For: (Peter Galko) (Department of Electrical Engineering)
  175. %        %%Title: (Test Figure)
  176. %        %%CreationDate: (12/13/91) (5:26 PM)
  177. %        %%BoundingBox: 137 587 492 686
  178. %        %%DocumentProcessColors:
  179. %        %%DocumentNeededResources: procset Adobe_packedarray 2.0 0
  180. %        %%+ procset Adobe_cmykcolor 1.1 0
  181. %        %%+ procset Adobe_cshow 1.1 0
  182. %        %%+ procset Adobe_customcolor 1.0 0
  183. %        %%+ procset Adobe_IllustratorA_AI3 1.0 1
  184. %        %AI3_ColorUsage: Black&White
  185. %        %AI3_TemplateBox: 306 396 306 396
  186. %        %AI3_TileBox: 30 31 582 761
  187. %        %AI3_DocumentPreview: None
  188. %        %%EndComments
  189. %        %%BeginProlog
  190. %        %%IncludeResource: procset Adobe_packedarray 2.0 0
  191. %        ...
  192. %
  193. % In this example, we see that the drawing has its lower left hand coordinates
  194. % at coordinates (137,587) and its upper right corner at (492,686).
  195. % The very first line indicates that it is an EPSF file conforming to the 3.0
  196. % specification. We also see lines here that state that the drawing is only in
  197. % black and white, there is no preview (a Quickdraw version of the figure) stored
  198. % in the file [which means that Textures would not be able to draw this figure in
  199. % its preview window; we could have added the Quickdraw version when the file was
  200. % save by Illustrator---it just wasn't done in this case].
  201. %
  202. % A good practice to follow in making drawings is to finish by drawing a box
  203. % around your object, and then setting the line thickness of the box to zero
  204. % and the line to be transparent to make the outlining box invisible (or in some
  205. % way leaving the box unstroked and unfilled); this box should then very nearly
  206. % correspond to the bounding box the application generating the figure should
  207. % specify.  Most graphic applications will specify the bounding box to be one to
  208. % two points larger than the drawn outline.  Often this is unimportant, but if
  209. % necessary can be found by reading the EPSF file using Textures itself or most
  210. % text file editors.  If the figure were drawn so that the lower left hand corner
  211. % of the drawn outline box was placed at the origin (something you can easily do
  212. % with Adobe Illustrator after the figure was already drawn), then the position of
  213. % the lower left-hand corner relative to the bounding box specified lower left-hand
  214. % corner is (-llx,-lly).  The bounding box specified in a file will be reported
  215. % in the Textures log file if you simply add the statement \epsfverbosetrue to the
  216. % the TeX file.
  217. %
  218. % Specifying PICT and EPSF objects
  219. % ================================
  220. % To 'input' a drawing into a typeset document, you make use of the \special
  221. % command in TeX. To import a PICT picture stored in the resource fork of the
  222. % document you simply issue the command
  223. %       \special picture 'name'
  224. % where 'name' is the name of the PICT object (no quotes appear in the command)
  225. % that you gave it when the object was copied into the pictures window. If the
  226. % PICT picture is stored as a separate resource, you simply issue the command
  227. %       \special pictfile 'name'
  228. % Similarly, you include an EPSF file by issuing the command
  229. %       \special illustration 'name'
  230. % where 'name' is replaced by the name (no quotes appear in the command unless
  231. % they are part of the file name [and colons have special significance in file
  232. % names which disallows them as part of a low level file name]) of the EPSF file
  233. % (which should be placed in the same folder as the Textures document;
  234. % otherwise you will have to specify the full directory name including the
  235. % volume name and hierarchy of folders). The lower left point of the bounding
  236. % box of the graphic object is then placed at the current point and the object
  237. % is drawn. Thus the current point must first be moved so that the drawing will
  238. % not overlap onto other output and otherwise be properly positioned. Some
  239. % macros which take care of the positioning and importation of PICT and EPSF
  240. % objects are given below. The macros center drawings on the current line
  241. % according to picture dimensions explicitly given to the macro.  The dimensions
  242. % of the bounding box of a graphic are not known to TeX, only to the printer
  243. % driver and previewer. Thus you can in practice give other dimensions for the
  244. % bounding box of the object if you want to shift the image on the page.  Doing
  245. % so however will change the dimensions of the box that you may want drawn
  246. % around the figure which may be undesireable.  You can shift the figure and
  247. % encompasing box without changing the box size by specifying a value for the
  248. % parameter \shiftleft just before a figure placement macro occurs.  For example,
  249. % saying '\shiftleft=1cm' just before invoking a figure placement macro will make
  250. % the figure shift to the left by one centimeter on the page.  In the case that
  251. % \rlth=0pt [i.e., no outline of the box is to be provided], the same effect could
  252. % have been had by increasing the indicated width of the figure by two
  253. % centimeters.
  254. %
  255. % Macro description and specification:
  256. % ===================================
  257. % The Figure Placement Macros:
  258. % ---------------------------
  259. % 1. The \figure macro
  260. % 2. The \scaledfigure macro
  261. % 3. The \epsffigure macro
  262. % 4. The \scaledepsffigue macro
  263. % 5. The \stretchedepsfigure macro
  264. %
  265. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  266. % The \figure macro creates a box of a specified inside dimension and then
  267. % puts the graphic object inside aligning the lower left inside corner with
  268. % the lower left corner of the bounding box of the object. The thickness
  269. % of the lines forming the box are given by the parameter \rlth, and setting 
  270. % this dimension to zero (the default value) results in the suppression
  271. % of the outlining box. The macro also allows further TeX material to be 
  272. % typeset on top of the figure (see the text placement macros below).
  273. %
  274. % Macro \figure #1 #2 by #3 #4 #5 #6 #7
  275. %   first argument:   a few letters indicating the type of graphic file
  276. %                     format---either "epsf", "pict" (for a PICT resource), or
  277. %                     "pictf" (for an external PICT file) is possible.
  278. %   second argument:  the horizontal width of the picture (a number with units
  279. %                     as in 1.23cm, 2.45in, 34.5pt, etc.)  
  280. %   third argument:   the vertical height of the picture (a number with units
  281. %                     as in 1.23cm, 2.45in, 34.5pt, etc.)  Specifying a zero
  282. %                     dimension causes the figure to be suppressed.
  283. %   fourth argument:  the name of the picture (resource or file).
  284. %   fifth argument:   extra information which can add text on top of a picture
  285. %                     (what appears here is TeXed relative to the lower left of
  286. %                     the bounding box)
  287. %   sixth argument:   the figure number (used as defined in the \fignostyle
  288. %                     macro: if this parameter is blank, figure numbers are
  289. %                     suppressed---otherwise the figure number is appended to
  290. %                     "Fig.~" in bold, and followed by \quad in the caption).
  291. %   seventh argument: the figure caption (if nothing is given, a caption is
  292. %                     suppressed, even if a figure number is specified). The
  293. %                     caption style is controlled by the \captionstyle macro, 
  294. %                     which is set to produce a single centered line if the
  295. %                     caption fits on one line, two lines centered one above
  296. %                     the other if the caption has two lines, and otherwise
  297. %                     produces a paragraph style caption. The caption width is
  298. %                     controlled by the dimension \captionwidth, which can be
  299. %                     specified before the call to this macro. At the end of
  300. %                     each use of this macro, \captionwidth is reset to
  301. %                     \normalcaptionsize (currently set to \hsize).  The intent
  302. %                     of this is to allow the user to avoid wide captions under
  303. %                     very narrow figures which can be unattractive. The line
  304. %                     spacing used in a caption is controlled by the parameter
  305. %                     \captionbaselineskip (the original value is 12pt
  306. %                     correspondind to single spacing in the normal
  307. %                     environment).
  308. %
  309. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  310. %
  311. % The \scaledfigure macro is a variation on the \figure macro. It has the 
  312. % identical function except that the dimensions and the like are scaled in
  313. % size.
  314. %
  315. % Macro \scaledfigure #1 scaled #2 #3 by #4 #5 #6 #7 #8
  316. %   first argument:   a few letters indicating the type of graphic file
  317. %                     format---either "epsf", "pict" (for a PICT resource), or
  318. %                     "pictf" (for an external PICT file) is possible.
  319. %   second argument:  an integer giving the scale in TeX units
  320. %                     (1000 = original size) 
  321. %   third argument:   the horizontal width of the picture before scaling (a
  322. %                     number with units as in 1.23cm, 2.45in, 34.5pt, etc.) 
  323. %   fourth argument:  the verticle height of the picture before scaling (a  
  324. %                     number with units as in 1.23cm, 2.45in, 34.5pt, etc.)
  325. %   fifth argument:   the name of the picture (resource or file)
  326. %   sixth argument:   extra information which can add text on top of a picture
  327. %                     (what appears here is TeXed relative to the lower left of
  328. %                     the bounding box). Dimensions used in the text placement
  329. %                     macros below are scaled too.
  330. %   seventh argument: the figure number (used as defined in the \fignostyle
  331. %                     macro: if this parameter is blank, figure numbers are
  332. %                     suppressed---otherwise the figure number is appended to
  333. %                     "Fig.~" in bold, and followed by \quad in the caption).
  334. %   eighth argument:  the figure caption (if nothing is given, a caption is
  335. %                     suppressed, even if a figure number is specified). The
  336. %                     caption style is controlled by the \captionstyle macro, 
  337. %                     which is set to produce a single centered line if the
  338. %                     caption fits on one line, two lines centered one above
  339. %                     the other if the caption has two lines, and otherwise
  340. %                     produces a paragraph style caption. The caption width is
  341. %                     controlled by the dimension \captionwidth, which can be
  342. %                     specified before the call to this macro. At the end of
  343. %                     each use of this macro, \captionwidth is reset to
  344. %                     \normalcaptionsize (currently set to \hsize). The line
  345. %                     spacing used in a caption is controlled by the parameter
  346. %                     \captionbaselineskip (the original value is 12pt
  347. %                     correspondind to single spacing in the normal
  348. %                     environment).
  349. %
  350. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  351. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  352. %
  353. % Automatic EPSF Macros
  354. % ---------------------
  355. % The \epsffigure macro is a version of the \figure macro which is only for EPSF
  356. % figures, and differs in that the figure dimensions are determined by Textures
  357. % from the bounding box specification in the EPSF file.  Thus the macro call does
  358. % not provide the figure dimensions.  In this and the following two macros, by
  359. % issueing a \epsfverbosetrue command, the macros can be made to report the size
  360. % of the bounding box for the EPSF files in the log file
  361. %
  362. % Macro \epsffigure #1 #2 #3 #4 
  363. %   first argument:   the name of the picture (resource or file)
  364. %   second argument:  extra information which can add text on top of a picture
  365. %                     (what appears here is TeXed relative to the lower left of
  366. %                     the bounding box). Dimensions used in the text placement
  367. %                     macros below are scaled too.
  368. %   third argument:   the figure number (used as defined in the \fignostyle
  369. %                     macro: if this parameter is blank, figure numbers are
  370. %                     suppressed---otherwise the figure number is appended to
  371. %                     "Fig.~" in bold, and followed by \quad in the caption).
  372. %   fourth argument:  the figure caption (if nothing is given, a caption is
  373. %                     suppressed, even if a figure number is specified). The
  374. %                     caption style is controlled by the \captionstyle macro, 
  375. %                     which is set to produce a single centered line if the
  376. %                     caption fits on one line, two lines centered one above
  377. %                     the other if the caption has two lines, and otherwise
  378. %                     produces a paragraph style caption. The caption width is
  379. %                     controlled by the dimension \captionwidth, which can be
  380. %                     specified before the call to this macro. At the end of
  381. %                     each use of this macro, \captionwidth is reset to
  382. %                     \normalcaptionsize (currently set to \hsize). The line
  383. %                     spacing used in a caption is controlled by the parameter
  384. %                     \captionbaselineskip (the original value is 12pt
  385. %                     correspondind to single spacing in the normal
  386. %                     environment).
  387. %
  388. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  389. %
  390. % The \scaledepsffigure macro is a version of the \epsffigure macro which
  391. % differs only in that the figure is scaled in size in the document.  Thus the
  392. % macro call does not include the figure dimensions.
  393. %
  394. % Macro \scaledepsffigure scaled #1 #2 #3 #4 #5 
  395. %   first argument:   an integer giving the scale in TeX units
  396. %                     (1000 = original size) 
  397. %   second argument:  the name of the picture (resource or file)
  398. %   third argument:   extra information which can add text on top of a picture
  399. %                     (what appears here is TeXed relative to the lower left of
  400. %                     the bounding box). Dimensions used in the text placement
  401. %                     macros below are scaled too.
  402. %   fourth argument:  the figure number (used as defined in the \fignostyle
  403. %                     macro: if this parameter is blank, figure numbers are
  404. %                     suppressed---otherwise the figure number is appended to
  405. %                     "Fig.~" in bold, and followed by \quad in the caption).
  406. %   fifth argument:   the figure caption (if nothing is given, a caption is
  407. %                     suppressed, even if a figure number is specified). The
  408. %                     caption style is controlled by the \captionstyle macro, 
  409. %                     which is set to produce a single centered line if the
  410. %                     caption fits on one line, two lines centered one above
  411. %                     the other if the caption has two lines, and otherwise
  412. %                     produces a paragraph style caption. The caption width is
  413. %                     controlled by the dimension \captionwidth, which can be
  414. %                     specified before the call to this macro. At the end of
  415. %                     each use of this macro, \captionwidth is reset to
  416. %                     \normalcaptionsize (currently set to \hsize).   The line
  417. %                     spacing used in a caption is controlled by the parameter
  418. %                     \captionbaselineskip (the original value is 12pt
  419. %                     correspondind to single spacing in the normal
  420. %                     environment).
  421. %
  422. %
  423. % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  424. %
  425. % The \stretchedepsffigure macro is a version of the \epsffigure macro which
  426. % allows the figure to be scaled in different ways to fit a specified size. 
  427. % This allows only the contents of the EPSF file to be stretched, not
  428. % the overlayed text. These effects will appear only in the printed output,
  429. % although if a figure box is displayed, on the Macintosh's screen it will be
  430. % have the proper dimensions and have its lower left hand corner appear in the
  431. % same location as does the final box on the page.  The macro allows the 
  432. % specification of the final width of the bounding box of the scaled drawing or
  433. % the final height of the scaled drawing and possibly both.  When only one
  434. % final dimension is specified, the figure is scaled uniformly in both
  435. % directions.  When both final sizes are specified, the figure is scaled
  436. % independently in the two directions. 
  437. %
  438. % Macro \stretchedepsffigure #1 by #2 #3 #4 #5 #6 
  439. %   first argument:   the desired final horizontal width of the picture (a number
  440. %                     with units as in 1.23cm, 2.45in, 34.5pt, etc.)  If a zero
  441. %                     is specified, then the final horizontal width is computed
  442. %                     from uniformly scaling the figure to have a height
  443. %                     specified by the second parameter.  If both parameters are
  444. %                     zero, then the figure is suppressed (although a caption 
  445. %                     will remain).
  446. %   second argument:  the desired final vertical height of the picture (a number
  447. %                     with units as in 1.23cm, 2.45in, 34.5pt, etc.)  If a zero
  448. %                     is specified, then the final vertical height is computed
  449. %                     from uniformly scaling the figure to have a width
  450. %                     specified by the first parameter.  If both parameters are
  451. %                     zero, then the figure is suppressed (although a caption 
  452. %                     will remain).
  453. %   third argument:   the name of the EPSF file.
  454. %   fourth argument:  extra information which can add text on top of a picture
  455. %                     (what appears here is TeXed relative to the lower left of
  456. %                     the bounding box)
  457. %   fifth argument:   the figure number (used as defined in the \fignostyle
  458. %                     macro: if this parameter is blank, figure numbers are
  459. %                     suppressed---otherwise the figure number is appended to
  460. %                     "Fig.~" in bold, and followed by \quad in the caption).
  461. %   sixth argument:   the figure caption (if nothing is given, a caption is
  462. %                     suppressed, even if a figure number is specified). The
  463. %                     caption style is controlled by the \captionstyle macro, 
  464. %                     which is set to produce a single centered line if the
  465. %                     caption fits on one line, two lines centered one above
  466. %                     the other if the caption has two lines, and otherwise
  467. %                     produces a paragraph style caption. The caption width is
  468. %                     controlled by the dimension \captionwidth, which can be
  469. %                     specified before the call to this macro. At the end of
  470. %                     each use of this macro, \captionwidth is reset to
  471. %                     \normalcaptionsize (currently set to \hsize).  The line
  472. %                     spacing used in a caption is controlled by the parameter
  473. %                     \captionbaselineskip (the original value is 12pt
  474. %                     correspondind to single spacing in the normal
  475. %                     environment).
  476. %
  477. %
  478. % Macro Definitions
  479. % ===============================================================================
  480. %
  481. \catcode`\@=11
  482. \newskip\prefigureskip \newskip\prefigureskipshort
  483. \newskip\postfigureskip \newskip\prefiglabel 
  484. %
  485. % \prefigureskip defines the space between the material before a figure and
  486. %    the top of the figure itself when the figure is wide
  487. % \prefigureskipshort defines the space between the material before a figure
  488. %    and the top of the figure itself when the figure is narrow
  489. \prefigureskip=10pt plus3pt minus2pt \prefigureskipshort=2pt plus3pt minus1pt
  490. % all the glue below is used with any baselineskip glue suppressed
  491. % \prefiglabel defines the glue between outlininging box and figure label
  492. % \postfiglabel defines the glue between the figure caption and the material
  493. %  following (from the bounding box to the following material when the figure
  494. %  caption is supressed)
  495. \prefiglabel=4pt \postfigureskip=16pt plus 2ptminus 2pt
  496. %
  497. \newdimen\rlth \newcount\lines \rlth=0pt \def\nothing{} \newdimen\figwidth 
  498. \newcount\count@@ \newcount\cnt@ \newcount\cnt@@ \newcount\cnt@@@
  499. \newdimen\captionwidth \newdimen\captionbaselineskip \captionbaselineskip=12pt
  500. \newdimen\leftshift \leftshift=0pt
  501. \newcount\scalefx \newcount\scalefy \scalefx=1000 \scalefy=1000
  502. \newdimen\normalcaptionwidth \normalcaptionwidth=\hsize
  503. \captionwidth=\normalcaptionwidth
  504. \def\@epsf{epsf} \def\@pict{pict} \def\@pictf{pictf}
  505. \newdimen\xoffset \newdimen\yoffset \xoffset=0pt \yoffset=0pt
  506. %
  507. \def\figure #1 #2 by #3 #4 #5 #6 #7{{\def\@ft{#1}
  508. \global\scalefx=1000\global\scalefy=1000
  509. $$
  510. \abovedisplayskip=\prefigureskip \belowdisplayskip=0pt 
  511. \lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
  512. \belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
  513. \dimen0=#3
  514. \ifdim\dimen0 = 0pt\else 
  515.   \vbox{\hmaxbox to \hsize{\vrule width\rlth
  516.     \vbox to#3{\offinterlineskip\hrule width#2 height\rlth
  517.       \vbox to 0pt{\hrule width#2 height 0pt\vskip#3
  518.       \ifx \@ft\@pict\special{picture #4}
  519.        \else\ifx \@ft\@epsf\special{illustration #4}
  520.         \else\ifx \@ft\@pictf\special{pictfile #4}
  521.          \else\message{Illegal use of figure macro. The first argument should be}
  522.               \message{'pict' (for a PICT image stored in the Textures file),}
  523.               \message{'pictf' (for a PICT image stored as a separate file), or}
  524.               \message{'epsf' (for an EPSF image stored in a separate file from}
  525.               \message{the Textures file).}\fi\fi\fi
  526.       #5\vss}\vfill\hrule height \rlth
  527.     }\vrule width \rlth\hskip 2\leftshift}\par}
  528. \fi
  529. $$\par
  530. \xdef\figcaption{#7} \ifx\figcaption\nothing\else\captionstyle{#6}{#7}\fi
  531. \vskip\postfigureskip} \nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}
  532. %
  533. \def\fignostyle#1{\xdef\figno{#1}\if\figno\nothing \else{\bf Fig.~#1.}\quad\fi}
  534. \def\captionstyle#1#2{\vskip \prefiglabel \nointerlineskip
  535.  {\hsize=\captionwidth \baselineskip=\captionbaselineskip
  536.  \parfillskip=0pt plus 1fil \parindent=0.0pt \parskip=0pt
  537.  \global\setbox1=\vtop{\hskip\parfillskip\fignostyle{#1}
  538.                  #2\par\global\lines=\prevgraf}}
  539.  \ifnum\lines=1\vtop{\centerline{\box1}}
  540.  \else
  541.   \ifnum\lines=2\vtop{\centerline{\hsize=\captionwidth
  542.       \vtop{\leftskip=0pt plus 1fil \rightskip=0pt plus 1fil
  543.       \parfillskip=0pt\ignorespaces {\noindent\fignostyle{#1}} #2\vskip 0pt}}}
  544.   \else \vtop{\centerline{\hsize=\captionwidth
  545.    \vtop{\leftskip=0.3in \hskip -0.3in\fignostyle{#1} #2\vskip 0pt}}}
  546.   \fi
  547.  \fi \captionwidth=\normalcaptionwidth}
  548. %
  549. \def\hmaxbox to #1#2{\setbox2 = \hbox{#2} 
  550.  \ifdim \wd2>#1 \hbox to #1{\hss\box2\hss} \global\figwidth=#1
  551.   \else \box2 \global\figwidth=\wd2 
  552.   \fi}
  553. %
  554. %%
  555. %
  556. \def\scaledfigure #1 scaled #2 #3 by #4 #5 #6 #7 #8{{\def\@ft{#1}
  557. \global\scalefx=#2\global\scalefy=#2
  558. $$
  559. \abovedisplayskip=\prefigureskip \belowdisplayskip=0pt
  560. \lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
  561. \belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
  562. \dimen0=#3 \dimen1=#4 \divide\dimen0 by 1000 \divide\dimen1 by 1000
  563. \multiply\dimen0 by #2 \multiply\dimen1 by #2
  564. \vbox{\hmaxbox to \hsize {\vrule width\rlth
  565.   \vbox to\dimen1{\offinterlineskip\hrule width\dimen0 height\rlth
  566.     \vbox to 0pt{\hrule width\dimen0 height 0pt\vskip\dimen1
  567.     \ifx \@ft\@pict \special{picture #5 scaled #2}
  568.      \else\ifx \@ft\@epsf \special{illustration #5 scaled #2}
  569.       \else\ifx \@ft\@pictf\special{pictfile #5}
  570.        \else\message{Illegal use of figure macro. The first argument should be}
  571.             \message{'pict' (for a PICT image stored in the Textures file),}
  572.             \message{'pictf' (for a PICT image stored as a separate file), or}
  573.             \message{'epsf' (for an EPSF image stored in a separate file from}
  574.             \message{the Textures file).}\fi\fi\fi
  575.     #6\vss}\vfill\hrule height \rlth
  576.   }\vrule width \rlth\hskip 2\leftshift}\par}
  577. $$\par
  578. \xdef\figcaption{#8} \ifx \figcaption\nothing\else\captionstyle{#7}{#8}\fi
  579. \vskip\postfigureskip}
  580. \nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}
  581. %
  582. %%
  583. %
  584. \def\epsffigure #1 #2 #3 #4{\epsfgetbb{#1}
  585.     \ifepsfbbfound
  586.         \ifepsfbbNAN
  587.             \figure epsf 0pt by 0pt {#1} {#2} {#3} {#4}
  588.         \else 
  589.             \figure epsf {\the\epsfwidth} by {\the\epsfheight} {#1} {#2} {#3} {#4}
  590.         \fi
  591.     \else
  592.         \figure epsf 0pt by 0pt {#1} {#2} {#3} {#4}
  593.     \fi}
  594.  
  595. \def\scaledepsffigure scaled #1 #2 #3 #4 #5{\epsfgetbb{#2}
  596.     \ifepsfbbfound
  597.         \ifepsfbbNAN
  598.             \figure epsf 0pt by 0pt {#2} {#3} {#4} {#5}
  599.         \else
  600.             \scaledfigure epsf scaled #1 {\the\epsfwidth} by {\the\epsfheight} {#2} 
  601.                 {#3} {#4} {#5}\fi
  602.     \else
  603.         \figure epsf 0pt by 0pt {#2} {#3} {#4} {#5}
  604.     \fi}
  605. %
  606. %  If you want TeX to report the size of the figure (as a message
  607. %   on your terminal when it processes each figure), say `\epsfverbosetrue'.
  608. %
  609. \newread\epsffilein      % file to \read
  610. \newdimen\epsfwidth      % figure width
  611. \newdimen\epsfheight     % figure height
  612. \newif\ifepsffilereadon  % continue looking for the bounding box?
  613. \newif\ifepsfbbfound     % bounding box comment found
  614. \newif\ifepsfbbNAN       % bounding box is not specified
  615. \newif\ifepsfverbose     % report what you're making?
  616. {\catcode`\%=12 \global\def\pcnt{%}}
  617. %
  618. \def\epsfgetbb#1{%
  619. %
  620. %   The first thing we need to do is to open the
  621. %   PostScript file, if possible.
  622. %
  623.     \openin\epsffilein=#1
  624.     \ifeof\epsffilein\errmessage{I couldn't open the file #1.  I am ignoring the figure}
  625.     \else
  626. %
  627. %   Okay, we got it. Now we'll scan lines until we find one that doesn't
  628. %   start with %. We're looking for the bounding box comment.
  629. %
  630.       {\epsffilereadontrue \chardef\other=12
  631.        \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
  632.        \loop
  633.            \read\epsffilein to \epsffileline
  634.            \ifeof\epsffilein\epsffilereadonfalse
  635.            \else
  636. %
  637. %   We check to see if the first character is a % sign;
  638. %   if not, we stop reading (unless the line was entirely blank);
  639. %   if so, we look further and stop only if the line begins with
  640. %   `%%BoundingBox:'.
  641. %
  642.                \expandafter\epsfaux\epsffileline:. \\%
  643.            \fi
  644.            \ifepsffilereadon\repeat
  645.        \ifepsfverbose
  646.            \ifepsfbbfound
  647.               \immediate\write16{The bounding box comment in the file "#1" is:"}
  648.               \immediate\write16{\space\space\space"\pcnt\pcnt BoundingBox \epsfllx\space%
  649.                        \epsflly\space\epsfurx\space\epsfury"}
  650.            \else
  651.               \immediate\write16{No bounding box comment found in "#1".  The figure is ignored}
  652.            \fi
  653.        \else\fi
  654.        \ifepsfbbNAN
  655.            \immediate\write16{The bounding box values in "#1" are unknown.  The figure is ignored.}\fi
  656.        }
  657.        \closein\epsffilein
  658.     \fi}%
  659. %
  660. %   We still need to define the tricky \epsfaux macro. This requires
  661. %   a couple of magic constants for comparison purposes.
  662. %
  663. {\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox}}%
  664. %
  665. %   So we're ready to check for `%BoundingBox:' and to grab the
  666. %   values if they are found.
  667. %
  668. \long\def\epsfaux#1#2:#3\\{
  669.    \ifx#1\epsfpercent
  670.        \def\testit{#2}
  671.        \ifx\testit\epsfbblit
  672.            \epsffilereadonfalse
  673.            \global\epsfbbfoundtrue
  674.            \epsfgrab #3 . . . \\%
  675.        \else\fi
  676.    \else
  677.        \ifx#1\par                    % stop reading the file if a noncomment
  678.        \else\epsffilereadonfalse\fi  % nonblank line is found in the file
  679.    \fi}%
  680. %
  681. %   Here we grab the values and stuff them in the appropriate definitions.
  682. %
  683. \def\epsfgrab #1 #2 #3 #4 #5\\{%
  684.    \global\def\epsfllx{#1}
  685.    \ifx\epsfllx\empty
  686.        \epsfgrab #2 #3 #4 #5 .\\
  687.    \else
  688.        \global\def\epsflly{#2}
  689.        \global\def\epsfurx{#3}
  690.        \global\def\epsfury{#4}
  691.        \epsfbbNANfalse
  692.        \checkifnumber{#1}\checkifnumber{#2}\checkifnumber{#3}\checkifnumber{#4}
  693.        \ifepsfbbNAN
  694.        \else
  695.           {\epsfwidth=#3 bp\dimen0=#1 bp\global\advance\epsfwidth by -\dimen0
  696.            \epsfheight=#4 bp\dimen0=#2 bp\global\advance\epsfheight by -\dimen0}
  697.        \fi
  698.    \fi}%
  699. %
  700. % The macros below will check if a string is a real number or not.  Spaces in the
  701. % string are ignored entirely.  Thus "1 1" is a number, as is "+5", "-3.0",
  702. % but not "++6", nor "1.2.0".  When a nonnumber is encountered, the command \epsfbbNANtrue
  703. % is executed.  
  704. %
  705. \newif\ifstartnumber \newif\ifnodecimalpt 
  706. \def\checkifnumber#1{\count@=0 \startnumbertrue\nodecimalpttrue\checknumber#1\end
  707.     \ifnum\count@=0 \global\epsfbbNANtrue\else\fi}
  708. \def\checknumber#1{
  709.    \ifx#1\end\let\next=\relax
  710.    \else
  711.        \let\next=\checknumber
  712.        \advance\count@ by 1                          % count the number of digits
  713.        \count@@=`#1 
  714.        \ifepsfbbNAN
  715.        \else
  716.            \ifnum\count@@ > 47                        % ASCII for digits is 48 -- 57
  717.                \ifnum\count@@ < 58 \startnumberfalse
  718.                \else \global\epsfbbNANtrue\fi
  719.            \else
  720.                \if#1.                                % check for a decimal point possibility
  721.                    \startnumberfalse
  722.                    \advance\count@ by -1
  723.                    \ifnodecimalpt
  724.                        \nodecimalptfalse
  725.                    \else
  726.                        \global\epsfbbNANtrue
  727.                    \fi
  728.                \else
  729.                    \ifstartnumber                    % check for a leading sign
  730.                        \if#1+
  731.                            \startnumberfalse
  732.                            \advance\count@ by -1
  733.                        \else
  734.                            \if#1-
  735.                                \startnumberfalse
  736.                                \advance\count@ by -1
  737.                            \else
  738.                                \global\epsfbbNANtrue
  739.                            \fi
  740.                        \fi
  741.                    \else
  742.                        \global\epsfbbNANtrue
  743.                    \fi
  744.                \fi
  745.            \fi
  746.        \fi
  747.    \fi
  748.    \next}
  749. %
  750. %
  751. %
  752. % The Text Placement Macros
  753. % -------------------------
  754. % A common problem one encounters in drawing objects relates to drawing in text.
  755. % This is especially true in adding mathematics to a figure, or when one wants 
  756. % to label a figure's elements using the CM fonts which are only available in
  757. % TeX (except for the CM fonts rendered in Postscript form which can be
  758. % accessed just as any other Macintosh font). To accomplish this, the following
  759. % macros may be used to position material relative to a reference point which is 
  760. % initially at the lower left hand corner of the the bounding box of the
  761. % drawing. You simply specify to the appropriate macro how far to move (up and to
  762. % the right are positive directions) and how to position text about the "end"
  763. % location (either left, centered, or right justified horizontally, and with the
  764. % baseline, textaxis (defined by considering the x-height of the current font) 
  765. % or mathaxis at the end point, or with vertical top or bottom justification or
  766. % centering). The text can also be rotated about the end point, although this is
  767. % done by going behind Texture's back by sending unexpected PostScript stuff to
  768. % the LaserWriter to acheive the effect. As a result, rotation thus works only
  769. % on PostScript printers.
  770. %
  771. % Macro \position #1 #2 #3 by #4 #5 #6
  772. %   first argument:  one of the words "left", "center", or "right" to
  773. %                    indicate how the material of #6 is to be centered in the 
  774. %                    horizontal ("left" means that the material is left
  775. %                    justified where the left vertical edge of the 
  776. %                    material is at the end point; "right" and
  777. %                    "center" have similar corresponding meanings.)
  778. %   second argument: one of the words "top", "center", "bottom", "baseline",
  779. %                    "mathaxis", or "textaxis" to indicate how the material is 
  780. %                    to be positioned vertically. "top" means that the top of
  781. %                    the box enclosing the material of #6 is placed at the level
  782. %                    of the end point, with "bottom" and "center" having
  783. %                    similar corresponding meanings. "mathaxis" means that the
  784. %                    normal position of the mathaxis of material specified 
  785. %                    by \fontdimen22 of \textfont2 is placed at the level
  786. %                    of the displaced point; "textaxis" means that the
  787. %                    material is placed so that the midpoint of a letter "x"
  788. %                    from \texfont0 would be at the level of the displaced
  789. %                    point. Anything else (including "baseline") will have
  790. %                    the baseline positioned at the level of the displaced
  791. %                    point.
  792. %   third argument:  the horizontal displacement (a number with units as in
  793. %                    1.23cm, 2.45in, 34.5pt, etc.) from the reference point
  794. %                    to the end point for the material to be added. The
  795. %                    actual displacement will be this value scaled by the
  796. %                    scale factor in \scaledfigure or \scaledepsffigure or 
  797. %                    the effective horizontal scalefactor in
  798. %                    \stretchedepsffigure if any of these macros are used.
  799. %   fourth argument: the verticle displacement (a number with units as in
  800. %                    1.23cm, 2.45in, 34.5pt, etc.) from the reference point
  801. %                    to the end point for the material to be added. The
  802. %                    actual displacement will be this value scaled by the
  803. %                    scale factor in \scaledfigure or \scaledepsffigure or 
  804. %                    the effective horizontal scalefactor in
  805. %                    \stretchedepsffigure if any of these macros are used.
  806. %   fifth argument:  the rotation in degrees counter-clockwise of the material
  807. %                    of #6 about the displaced point to be applied (the 
  808. %                    rotation does not appear in the preview).
  809. %   sixth argument:  the text to be overlayed on the picture.
  810. %
  811. %
  812. % The \reposition macro simply moves the reference point so that if the lower
  813. % left hand corner of the bounding box isn't where it was thought to be, the
  814. % reference point can in fact be moved to the position desired. The bounding
  815. % box of a picture is specified by the program that generates the drawing, and
  816. % is not always in predictable locations, hence the need for this macro. For
  817. % example, if you draw a simple rectangular box in Adobe Illustrator, and
  818. % perhaps just paint the box insides or even leave the box unpainted,
  819. % Illustrator does not specify the coordinates of the box corners as the
  820. % bounding box, but rather seems to indicate the bounding box is a slightly
  821. % larger box encompasing the drawn box. This is a small difference which can
  822. % be noticeable in some situations (the location of the bounding box can be
  823. % found for an EPSF file by reading the comments in header part of the EPSF
  824. % file or by specifying \epsfverbosetrue before using the \epsffigure macro
  825. % and reading the TeX log file produced by Textures).
  826. %
  827. % Macro \reposition #1 by #2
  828. %   first argument:  the horizontal displacement (a number with units as in
  829. %                    1.23cm, 2.45in, 34.5pt, etc.) from the lower left hand 
  830. %                    corner of the bounding box to where the reference point is
  831. %                    to be positioned. The final position will be this value
  832. %                    scaled by the scale factor in \scaledfigure if this macro
  833. %                    is being used.
  834. %   forth argument:  the verticle displacement (a number with units as in
  835. %                    1.23cm, 2.45in, 34.5pt, etc.) from the lower left hand 
  836. %                    corner of the bounding box to where the reference point is
  837. %                    to be positioned. The final position will be this value
  838. %                    scaled by the scale factor in \scaledfigure if this macro
  839. %                    is being used.
  840. %
  841. % The \incposition macro is the same as \reposition, only its effects are 
  842. % relative to the last position of the reference point and not to the lower 
  843. % left corner of the original bounding box.  This can be particularly useful
  844. % in figures that are actually composed of subfigures.
  845. %
  846. % Macro \incposition #1 by #2
  847. %   first argument:  the horizontal displacement (a number with units as in
  848. %                    1.23cm, 2.45in, 34.5pt, etc.) from the current position 
  849. %                    of the reference point to where the reference point is 
  850. %                    to be positioned. The final position of the reference
  851. %                    will be the current position of the reference point 
  852. %                    shifted by this value scaled by the scale factor in 
  853. %                    \scaledfigure.                    
  854. %   forth argument:  the verticle displacement (a number with units as in
  855. %                    1.23cm, 2.45in, 34.5pt, etc.) from the current position 
  856. %                    of the reference point to where the reference point is 
  857. %                    to be positioned. The final position of the reference
  858. %                    will be the current position of the reference point 
  859. %                    shifted by this value scaled by the scale factor in 
  860. %                    \scaledfigure.
  861. %               
  862. % AN EXAMPLE
  863. % ==========
  864. % An example of a figure in EPSF file being imported with text added using the 
  865. % macros defined here. The figure is stored in an EPSF file with name
  866. % "TestFigure" and has the axes labeled with TeX, and other comments added. The
  867. % figure is scaled up by 10% from the version in the EPSF file. A simple caption
  868. % is added.  The figure was generated using Illustrator 3.2.
  869. %
  870. % \scaledfigure epsf scaled 1100 13.0cm by 5.25cm TestFigure {
  871. %  \reposition 1bp by 1bp %the bounding box is off by this much
  872. %  \position right baseline 1.9cm by 3.5cm 0
  873. %  {$\matrix{\hbox{generated}\cr\hbox{number}\cr (r_n)\cr}$}
  874. %  \position left baseline 5.5cm by 0.25cm 0 {\hbox{seed \ \ $(r_{n-1})$}}
  875. %  \position right textaxis 1.90cm by 4.50cm 0 {$N$}
  876. %  \position center top 9.00cm by 0.4cm 0 {$N$}
  877. %  \position center top 2.00cm by 0.4cm 0 {$0$}
  878. %  \position left center 9.6cm by 3.5cm 0 {$\matrix{\hbox{($N$ is typically
  879. %   the}\hfill\cr \hbox{maximum value}\hfill\cr
  880. %   \hbox{representable in}\hfill\cr
  881. %   \hbox{the computer)}\hfill\cr}$}} 1 {The Multiplicative Congruential Method}
  882. %
  883. \def\@c{center} \def\@r{right} \def\@l{left} \def\@t{top} \def\@b{bottom}
  884. \def\@a{mathaxis} \def\@x{textaxis} \def\@zero{0}
  885. %
  886. \def\position #1 #2 #3 by #4 #5 #6{{
  887. % the next few lines of the macro are some contortions performed to get TeX
  888. % to scale the dimensions given in #3 and #4 accurately given that there is
  889. % a limit on the size of dimensions of 2**30 sp and only integer arithmetic 
  890. % available. (This is based on the fact that all dimension arithmetic is
  891. % done in terms of values specified in small points, and the integer 
  892. % division is truncated, not rounded.)  The result is the correctly rounded
  893. % scaled value.
  894. \dimen0=#3 \dimen3=\dimen0 \divide\dimen0 by 1000 \dimen2=\dimen0
  895.  \multiply\dimen0 by \scalefx \multiply\dimen2 by -1000 \advance\dimen2 by \dimen3
  896.  \multiply\dimen2 by \scalefx 
  897.  \ifdim\dimen2 > 0pt \advance\dimen2 by 500sp \else\advance\dimen2 by -500sp\fi
  898.  \divide\dimen2 by 1000 \advance\dimen0 by \dimen2 
  899. \dimen1=#4 \dimen3=\dimen1 \divide\dimen1 by 1000 \dimen2=\dimen1
  900.  \multiply\dimen1 by \scalefy \multiply\dimen2 by -1000 \advance\dimen2 by \dimen3
  901.  \multiply\dimen2 by \scalefy 
  902.  \ifdim\dimen2 > 0pt \advance\dimen2 by 500sp \else\advance\dimen2 by -500sp\fi
  903.  \divide\dimen2 by 1000 \advance\dimen1 by \dimen2
  904. \def\arga{#1}\def\argb{#2} \def\angle{#5}
  905. \ifx \argb\@a \setbox0=\hbox{\lower\the\fontdimen22\textfont2\hbox{#6}}
  906.  \else\ifx \argb\@c \setbox0=\hbox{\lower \the\fontdimen22\textfont2 
  907.                                     \hbox{$\vcenter{\hbox{#6}}$}}
  908.   \else\ifx \argb\@t \setbox0=\hbox{\vtop{\kern 0pt\hbox{#6}}}
  909.    \else\ifx \argb\@b \setbox0=\hbox{\vbox{\hbox{#6}\kern 0pt}}
  910.     \else\ifx \argb\@x \setbox0=\hbox{\lower 0.5ex\hbox{#6}}
  911.    \else\setbox0=\hbox{#6} \fi\fi\fi\fi\fi
  912. \setbox1=\hbox to 0pt{\ifx\arga\@l\else\hss\fi \box0
  913. \ifx \arga\@r\else\hss\fi} \dp1=0pt 
  914. \vbox to 0pt{\vss\hbox to 0pt{\kern\xoffset\kern \dimen0
  915.      \ifx\zero\angle\box1\else{\rotate #5 \box1}\fi\hss}
  916.      \vskip\yoffset\vskip \dimen1}
  917. \nointerlineskip}}
  918. %
  919. % The macro that does the rotation is due to Charles Karney:
  920. %%
  921. %% Rotation of TeX output with Textures (and maybe? other PostScript drivers)
  922. %%
  923. %% Written by
  924. %%   Charles Karney
  925. %%   Plasma Physics Laboratory   Phone:   +1 609 243 2607
  926. %%   Princeton University        MFEnet:  Karney@PPC.MFEnet
  927. %%   PO Box 451                  ARPAnet: Karney%%PPC.MFEnet@NMFECC.ARPA
  928. %%   Princeton, NJ 08543-0451    Bitnet:  Karney%%PPC.MFEnet@ANLVMS.Bitnet
  929. %%
  930. %% The following assumptions are made about the PostScript that TeXtures
  931. %% generates:
  932. %% (1) A single transform is used for all TeXtures output.
  933. %% (2) The PostScript \special is bracketed by gsave ... grestore.
  934. %% (3) Immediately after the gsave, the coordinate system is translated so the
  935. %%     origin is at the current point; and the y axis is flipped.
  936. %% (4) TeXtures doesn't leave anything on the stack for long periods. (This
  937. %%     simplifies restoring the default coordinate system.)
  938. %%
  939. %% Usage:
  940. %%   abc {\rotate 90 def} ghi
  941. %% On a non-postscript printer this will print the same as ``abc def ghi''.
  942. %% With TeXtures, the ``abc'' and ``ghi'' will appear on the page in the
  943. %% same place as before, however the ``def'' is bodily rotated counter-
  944. %% clockwise by 90 degrees. The rotation is about the bottom left corner of
  945. %% the ``d''. The braces serve to delimit the extent of the rotated text.
  946. %% The rotation angle is specified as an integer number of degrees. It can
  947. %% be negative. \rotate should always appear within a group (not at top-
  948. %% level). Rotations can be stacked, e.g.,
  949. %%   abc {\rotate 90 def \rotate 90 ghi} jkl
  950. %% would print as
  951. %%   ihg
  952. %%      f
  953. %%      e
  954. %%      d
  955. %%   abc         jlk
  956. %% except that the letters ``def'' would be sideways, and ``ghi'' would be
  957. %% upside down.
  958. %
  959. \def\rotate{\afterassignment\@rotate\count@}
  960. \def\@rotate{\aftergroup\@unrotate
  961. \special
  962. {postscript
  963.   0 0 transform                 % Get current location in device coordinates.
  964.   grestore                      % Undoes TeXtures gsave.
  965.   matrix currentmatrix          % Save current transform on stack for use
  966.                                 % by \@unrotate.
  967.   3 1 roll                      % Put transform at back of current location.
  968.   itransform                    % Current location in TeXtures coords
  969.   dup 3 -1 roll                 % Duplicate the location; x y ==> x y x y
  970.   dup 4 1 roll exch
  971.   translate                     % Translate origin to current location
  972.   1 -1 scale                    % Flip y coordinate
  973.   \the\count@\space rotate      % Rotate by \count@
  974.   1 -1 scale                    % Unflip y coordinate
  975.   neg exch neg exch translate   % Translate origin back
  976.   gsave}}                       % To match grestore
  977. \def\@unrotate{\special
  978. {postscript
  979.   grestore                      % Undoes Textures gsave
  980.   setmatrix                     % Set current transform to value saved on
  981.                                 % stack. (Hopefully, it's still there.)
  982.   gsave}}                       % To match grestore
  983. %
  984. % Below is a similar macro which allows stretching and rotation of material.
  985. % It stretches material by the amount by the ratio of its first two arguments
  986. % in the x direction and by the ratio of the third and fourth in the y direction
  987. % and then rotates the object counterclockwise by the fifth argument (in degrees).
  988. % Textures will know nothing about the changes in the dimensions of material until
  989. % the material prints (the screen display will not reflect the transformation).
  990. % [Macro due to P. Galko]
  991. \def\transformation #1 #2 #3 #4 #5 {\dimen0=#1 \cnt@=\dimen0 
  992.   \dimen0=#2 \cnt@@=\dimen0 \dimen0=#3 \cnt@@@=\dimen0 
  993.   \dimen0=#4 \count@@=\dimen0 \count@=#5 \@transf}
  994. \def\@transf{\aftergroup\@untransf
  995. \special
  996. {postscript
  997.   0 0 transform                 % Get current location in device coordinates.
  998.   grestore                      % Undoes TeXtures gsave.
  999.   matrix currentmatrix          % Save current transform on stack for use
  1000.                                 % by \@unrotate.
  1001.   3 1 roll                      % Put transform at back of current location.
  1002.   itransform                    % Current location in Textures coords
  1003.   dup 3 -1 roll                 % Duplicate the location; x y ==> x y x y
  1004.   dup 4 1 roll exch
  1005.   translate                     % Translate origin to current location
  1006.   1 -1 scale                    % Flip y coordinate
  1007.   \the\count@ \space rotate     % Rotate by \count@
  1008.   \the\cnt@ \space 
  1009.   \the\cnt@@ \space div         % compute x scale factor (=#1/#2)
  1010.   \the\cnt@@@ \space 
  1011.   \the\count@@ \space div scale % compute y scale factor with flip (=#3/#4)
  1012.   1 -1 scale                    % Unflip y coordinate
  1013.   neg exch neg exch translate   % Translate origin back
  1014.   gsave}}                       % To match grestore
  1015. \def\@untransf{\special
  1016. {postscript
  1017.   grestore                      % Undoes Textures gsave
  1018.   setmatrix                     % Set current transform to value saved on
  1019.                                 % stack. (Hopefully, it's still there.)
  1020.   gsave}}                       % To match grestore
  1021. %\catcode`\@=12
  1022. %
  1023. \def\reposition #1 by #2 {\xoffset=#1 \dimen0=\xoffset
  1024.   \divide\xoffset by 1000 \dimen1=\xoffset \multiply\xoffset by \scalefx 
  1025.   \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefx
  1026.   \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  1027.   \divide\dimen0 by 1000 \advance\xoffset by \dimen0 
  1028.  \yoffset=#2 \dimen0=\yoffset
  1029.   \divide\yoffset by 1000 \dimen1=\yoffset \multiply\yoffset by \scalefy
  1030.   \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefy
  1031.   \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  1032.   \divide\dimen0 by 1000 \advance\yoffset by \dimen0 }
  1033. %
  1034. % The next macro is the same as \reposition, only its effects are relative to
  1035. % the last position and not to the original bounding box lower left corner.
  1036. %
  1037. \def\incposition #1 by #2 {\dimen2=\xoffset \xoffset=#1 \dimen0=\xoffset
  1038.   \divide\xoffset by 1000 \dimen1=\xoffset \multiply\xoffset by \scalefx 
  1039.   \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefx
  1040.   \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  1041.   \divide\dimen0 by 1000 \advance\xoffset by \dimen0\advance\xoffset by \dimen2
  1042.  \dimen2=\yoffset \yoffset=#2 \dimen0=\yoffset
  1043.   \divide\yoffset by 1000 \dimen1=\yoffset \multiply\yoffset by \scalefy
  1044.   \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefy
  1045.   \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  1046.   \divide\dimen0 by 1000 \advance\yoffset by \dimen0\advance\yoffset by \dimen2}
  1047. %
  1048. %
  1049. \def\stretchedepsffigure #1 by #2 #3 #4 #5 #6{
  1050. {\epsfgetbb{#3}
  1051. % First a few contortions to accurately compute scale factors in integer mils
  1052. % (integer out of 1000).  It is assumed that no dimensions involved are larger
  1053. % than (2**30)/10 sp or about 1638.4pt = 22.67in = 57.6cm.  If dimensions exceed
  1054. % this limit, one *MAY* experience some overflow in arithmetic computations.
  1055.  \dimen0=#1 \multiply\dimen0 by 10 \dimen1=\dimen0 \divide\dimen0 by \epsfwidth
  1056.    \scalefx=\dimen0 \count@=\scalefx \multiply\scalefx by 100 
  1057.    \advance\dimen1 by -\count@\epsfwidth
  1058.    \dimen0=\dimen1 \multiply\dimen0 by 10 \dimen1=\dimen0
  1059.    \divide\dimen0 by \epsfwidth \count@=\dimen0 \advance\dimen1 by -\count@\epsfwidth
  1060.    \multiply\count@ by 10\advance\scalefx by \count@ \multiply\dimen1 by 10
  1061.    \advance\dimen1 by 0.5\epsfwidth \divide\dimen1 by \epsfwidth 
  1062.    \advance\scalefx by \dimen1
  1063.  \dimen0=#2 \multiply\dimen0 by 10 \dimen1=\dimen0 \divide\dimen0 by \epsfheight
  1064.    \scalefy=\dimen0 \count@=\scalefy \multiply\scalefy by 100 
  1065.    \advance\dimen1 by -\count@\epsfheight
  1066.    \dimen0=\dimen1 \multiply\dimen0 by 10 \dimen1=\dimen0
  1067.    \divide\dimen0 by \epsfheight \count@=\dimen0 \advance\dimen1 by -\count@\epsfheight
  1068.    \multiply\count@ by 10\advance\scalefy by \count@ \multiply\dimen1 by 10
  1069.    \advance\dimen1 by 0.5\epsfheight \divide\dimen1 by \epsfheight 
  1070.    \advance\scalefy by \dimen1
  1071.  \dimen0=#1 \dimen1=#2
  1072.  \ifdim\dimen0=0sp
  1073.      \ifdim\dimen1=0sp
  1074.          \scalefx=1000 \scalefy=1000 
  1075.      \else
  1076.          \dimen0=\epsfwidth \dimen2=\dimen0 \divide\dimen2 by 1000
  1077.          \advance\dimen0 by -1000\dimen2 \multiply\dimen0 by \scalefy
  1078.          \divide\dimen0 by 1000 \advance\dimen0 by \scalefy\dimen2
  1079.          \scalefx=\scalefy
  1080.      \fi
  1081.  \else
  1082.      \ifdim\dimen1=0sp
  1083.          \dimen1=\epsfheight \dimen2=\dimen1 \divide\dimen2 by 1000         
  1084.          \advance\dimen1 by -1000\dimen2 \multiply\dimen1 by \scalefx
  1085.          \divide\dimen1 by 1000 \advance\dimen1 by \scalefx\dimen2
  1086.          \scalefy=\scalefx
  1087.      \else\fi
  1088.  \fi
  1089.  $$
  1090.  \abovedisplayskip=\prefigureskip \belowdisplayskip=0pt 
  1091.  \lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
  1092.  \belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
  1093.  \ifdim\dimen0 = 0pt
  1094.  \else 
  1095.      \vbox{
  1096.          \hmaxbox to \hsize{
  1097.              \ifdim\rlth=0pt\else\vrule width\rlth\fi
  1098.              \vbox to\dimen1{
  1099.                  \offinterlineskip\ifdim\rlth=0pt\else\hrule width\dimen0 height\rlth\fi
  1100.                  \vbox to 0pt{\hrule width \dimen0 height 0pt\vskip\dimen1
  1101.                               {\transformation #1 {\the\epsfwidth} #2 {\the\epsfheight} 0
  1102.                                \special{illustration #3}}
  1103.                               #4\vss}
  1104.                  \vfill\ifdim\rlth=0pt\else\hrule height \rlth\fi
  1105.                  }\ignorespaces
  1106.              \ifdim\rlth=0pt\else\vrule width\rlth\fi\hskip 2\leftshift
  1107.              }\par
  1108.          }
  1109.  \fi
  1110.  $$\par
  1111.  \xdef\figcaption{#6} \ifx\figcaption\nothing\else\captionstyle{#5}{#6}\fi
  1112.  \vskip\postfigureskip
  1113. }\nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}
  1114.  
  1115. \catcode`\@=12
  1116. \rlth=0pt
  1117.